//
//  MainTabBarController.swift
//  firstSwiftWeiBo
//
//  Created by Inverno on 16/12/5.
//  Copyright © 2016年 Inverno. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {

//    lazy var middleButton : UIButton = {
//        () -> UIButton in
//        let button = UIButton()
//        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: .Normal)
//        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: .Highlighted)
//        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: .Normal)
//        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: .Highlighted)
//        button.sizeToFit()
//        return button
//    }()
    
    lazy var middleButton = UIButton(imageName: "tabbar_compose_icon_add", imageNameH: "tabbar_compose_icon_add_highlighted", backgroundImageName: "tabbar_compose_button", backgroundImageNameH: "tabbar_compose_button_highlighted")
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupMiddleButton()
        
    }
    
    override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
        
    }

}

extension  MainTabBarController {
    
    func setupMiddleButton() -> Void {
        // 添加时间监听：
        // 1.Selector("方法名")
        // 2.直接"方法名"
        // 注意：如果那个方法是私有的private 必须在前面加上@objc,因为private申明的函数不会添加到方法列表中，@objc表明私有函数依旧添加在该类的方法列表中
//        middleButton.addTarget(self, action: Selector("middleButtonClicked"), forControlEvents: .TouchUpInside)
        middleButton.addTarget(self, action: "middleButtonClicked", forControlEvents: .TouchUpInside)
        tabBar.addSubview(middleButton)
        middleButton.center = CGPointMake(tabBar.center.x, tabBar.bounds.size
            .height * 0.5)
    }
}

extension MainTabBarController {
    @objc private func middleButtonClicked() {
        print("middleButtonClicked")
    }
}